{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}

<div class="p-3">
    <form class="layui-form gg-form-bar border-t border-x">
        <div class="layui-input-inline" style="width:300px;">
            <input type="text" name="nickname" placeholder="请输入设备IMEI" class="layui-input" autocomplete="off" />
        </div>
        <div class="layui-input-inline" style="width:120px;">
            <input type="text" class="layui-input" id="start_time" readonly placeholder="开始时间" name="start_time">
        </div>
        ~
        <div class="layui-input-inline" style="width:120px;">
            <input type="text" class="layui-input" id="end_time" readonly placeholder="结束时间" name="end_time">
        </div>
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
    </form>
    <div style="margin-top: 10px;font-size: 18px;font-weight: bold;">
        <div>
            <span>总计售酒量(ml)：</span>
            <span id="wine_num" style="color: red">{$conf.wine_num}</span>
        </div>
    </div>
    <table class="layui-hide" id="order" lay-filter="order"></table>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!--		<span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加订单">+ 添加订单</span>-->
    </div>
</script>
<div class="row col-sm-12" style="display:none;" id="show_div">
    <form class="layui-form model-form" lay-filter="submitForm2" style="margin-top: 10px">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">拒绝原因：</label>
                <div class="layui-input-inline">
                    <textarea name="explain" id="explain" placeholder="请输入拒绝原因" style="width:350px;" class="layui-textarea jian">{$info['explain']|default=''}</textarea>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 109px">
            <div class="layui-inline">
                <button class="layui-btn">提交</button>
            </div>
        </div>
    </form>
</div>
<script type="text/html" id="barDemo">
    <div class="layui-btn-group">
        {{#  if(d.sh_status == 1){ }}
        <a class="layui-btn layui-bg-0 layui-btn-xs" lay-event="tg">通过</a>
        <a class="layui-btn layui-btn-xs" lay-event="jj" data-id="{{ d.id }}">拒绝</a>
        {{#  } }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</a>
        <!--	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </div>
</script>
<script type="text/html" id="image">
    <img src="{{d.image}}" width="30" height="30" lay-event="image"/>
</script>
<script type="text/html" id="imagesArr">
    {{# if(d.images != ''){ }}
    {{# layui.each(d.images, function(index, item){ }}
    <img src="{{item}}" width="30" height="30"  lay-event="image"/>
    {{# }); }}
    {{# }else{}}
    暂无图片
    {{#}}}
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];
    function gouguInit() {
        var table = layui.table,tool = layui.tool,laydate = layui.laydate, form = layui.form;
        laydate.render({
            elem: '#start_time',
            type: 'date'
        });

        laydate.render({
            elem: '#end_time',
            type: 'date'
        });
        layui.pageTable = table.render({
            elem: '#order',
            title: '订单列表',
            toolbar: '#toolbarDemo',
            url: '/admin/stat/measure',
            page: true,
            limit: 20,
            // lineStyle:'height:auto',
            cellMinWidth: 60,
            cols: [
                [
                {
                    // fixed: 'left',
                    field: 'id',
                    title: '编号',
                    align: 'center',
                    width: 80
                },{
                    field: 'imei',
                    title: '设备IMEI',
                    align: 'center',
                },{
                    field: 'wine_num',
                    title: '售酒量(ml)',
                    align: 'center',
                },{
                    field: 'order_no',
                    title: '订单号',
                    align: 'center',
                },{
                    field: 'create_time',
                    title: '记录时间',
                    align: 'center',
                }
                ]
            ], parseData: function (res) {
                console.log(res)
                $('#wine_num').text(res.msg.wine_num);
            }
        });

        //监听表头工具栏事件
        table.on('toolbar(order)', function(obj){
            if (obj.event === 'add') {
                tool.side("/admin/order/add");
                return false;
            }
        });

        //监听表格行工具事件
        table.on('tool(order)', function(obj) {
            var data = obj.data;
            if (obj.event === 'read') {
                tool.side('/admin/order/read?id='+obj.data.id);
            }
            else if (obj.event === 'edit') {
                tool.side('/admin/order/edit?id='+obj.data.id);
            }
            else if (obj.event === 'tg') {
                layer.confirm('确认通过吗？', {
                    btn: ['确认', '取消'] //可以无限个按钮
                }, function(index, layero){
                    $.post('/admin/order/examine', {id:obj.data.id,type:1}, function(res) {
                        layer.msg('操作成功',{icon:1,time:1500},function(){
                            window.location.reload();
                        });
                    },'json');
                }, function(index){
                    console.log('取消')
                });
            }
            else if (obj.event === 'jj') {
                var id = $(this).data('id');
                var index = layer.open({
                    type: 1,
                    title: ['提示说明'],//数组第二项可以写任意css样式；如果你不想显示标题栏，你可以title: false
                    area: '500px',
                    content: $('#show_div'),
                    success:function(){
                        form.on('submit(submitForm2)', function (data) {
                            var explain = $("#explain").val();
                            $.post('/admin/order/examine', {type:2,id:id,refuse:explain}, function(res) {
                                layer.closeAll();
                                layer.msg('操作成功',{icon:1,time:1500},function(){
                                    window.location.reload();
                                });
                            },'json');
                            return false;
                        });
                    }
                })
            }
            else if (obj.event === 'del') {
                layer.confirm('确定要删除该记录吗?', {
                    icon: 3,
                    title: '提示'
                }, function(index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    }
                    tool.delete("/admin/order/del", { id: data.id }, callback);
                    layer.close(index);
                });
            }
            if(obj.event === 'image')
            {
                var src = $(this).attr('src');
                // 在此处输入 layer 的任意代码
                layer.open({
                    type: 1, // page 层类型
                    area: ['500px', '500px'],
                    title: '',
                    shade: 0.6, // 遮罩透明度
                    shadeClose: true, // 点击遮罩区域，关闭弹层
                    maxmin: true, // 允许全屏最小化
                    anim: 0, // 0-6 的动画形式，-1 不开启
                    content: "<img src="+src+" style='width: 100%;'>"
                });
            }
            return false;
        });

        //监听搜索提交
        form.on('submit(searchform)', function(data) {
            layui.pageTable.reload({
                where: {
                    nickname: data.field.nickname,
                    start_time: data.field.start_time,
                    end_time: data.field.end_time,
                },
                page: {
                    curr: 1
                }
            });
            return false;
        });
    }
</script>
{/block}
<!-- /脚本 -->